package cn.edu.ncut.cs.springboot.petmanagementsystem.mapper;

import cn.edu.ncut.cs.springboot.petmanagementsystem.pojo.SearchHistory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 搜索历史Mapper
 */
@Mapper
public interface SearchHistoryMapper extends BaseMapper<SearchHistory> {
    
    /**
     * 获取热门搜索关键词
     * @param limit 限制数量
     * @return 热门关键词列表
     */
    @Select("SELECT keyword, SUM(search_count) as total_count " +
            "FROM search_history " +
            "GROUP BY keyword " +
            "ORDER BY total_count DESC " +
            "LIMIT #{limit}")
    List<String> getHotKeywords(@Param("limit") int limit);
    
    /**
     * 获取用户搜索历史
     * @param userId 用户ID
     * @param limit 限制数量
     * @return 搜索历史列表
     */
    @Select("SELECT * FROM search_history " +
            "WHERE user_id = #{userId} " +
            "ORDER BY update_time DESC " +
            "LIMIT #{limit}")
    List<SearchHistory> getUserSearchHistory(@Param("userId") Long userId, @Param("limit") int limit);
}
